<template>
  <div class="container_corporation">
    <div class="container_box">
      <el-form ref="form" :model="form" label-width="80px">

        <el-form-item label="公司Logo">
          <el-avatar :src="form.avatar"></el-avatar>
        </el-form-item>

        <el-form-item label="公司名称">
          <el-input v-model="form.name" style="width:300px" :disabled="flag"></el-input>
        </el-form-item>

        <el-form-item label="总裁头像">
          <el-avatar :src="form.ceoAvatar"></el-avatar>
        </el-form-item>

        <el-form-item label="公司总裁">
          <el-input v-model="form.ceoName" style="width:300px" :disabled="flag"></el-input>
        </el-form-item>

        <el-form-item label="手机号">
          <el-input v-model="form.ceoPhone" style="width:300px" :disabled="flag"></el-input>
        </el-form-item>

        <el-form-item label="企业类型">
          <el-input v-model="form.scale" style="width:300px" :disabled="flag"></el-input>
        </el-form-item>

        <el-form-item label="注册资金">
          <el-input v-model="form.registeredCapital" style="width:300px" :disabled="flag"></el-input>
        </el-form-item>

        <el-form-item label="公司简章">
          <el-input
              type="textarea" :rows="8" placeholder="请输入内容" style="width:300px" :disabled="flag" v-model="form.description">
          </el-input>
        </el-form-item>

        <el-form-item>
          <div style="padding:0 60px">
            <el-button type="primary" @click="editBtn" :disabled="flag">更新</el-button>
            <el-button @click="flag = false" v-if="flag">取消锁定</el-button>
            <el-button @click="flag = true" v-if="!flag">锁定</el-button>
          </div>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {company,edit} from "@/api/sys/company";

export default {
  data(){
    return{
      form:{},
      flag:true
    }
  },
  created() {
    this.getCompany()
  },

  methods:{
    async getCompany(){
      const {data:res}  = await company()
      this.form = res.data.company
    },
    async editBtn(){
      const {data:res} = await edit(this.form)
      console.log(res)
      if (res.code === 200 ){
        this.$message({
          message: '更新公司信息成功！',
          type: 'success'
        });
        await this.getCompany()
        this.flag = true
      }else {
        this.$message.error('更新公司信息失败！');
      }
    }

  }
}
</script>

<style scoped>
.container_corporation{
  width:1900px;
}
.container_box{
  margin:50px 40%
}
</style>
